package barrier;

import com.ibm.tspaces.TupleSpace;
import com.ibm.tspaces.TupleSpaceException;

public class Test {
  public static void main(String[] args) 
  throws TupleSpaceException, InterruptedException {
    int        rank  = Integer.parseInt(args[0]);
    int        total = Integer.parseInt(args[1]);
    TupleSpace ts    = new TupleSpace("barrierSpace", "localhost");
    
    if (rank == 0) {
      ts.deleteAll();
      for (int i = 0; i < 5; i++)
        new Barrier("barr"+i, ts).init();
    }
    
    Thread.sleep(5000);
    
    for (int i = 0; i < 5; i++) {
      System.out.printf("Client %d: print %d\n", rank, i);
      new Barrier("barr"+i, ts).barrier(total);
    }
    
    System.err.printf("Client %d finished.\n", rank);
  }
}
